package cn.gyouzhe.source.handlers;

import cn.gyouzhe.component.disruptor.AbstractHandler;
import cn.gyouzhe.entity.Seller;
import cn.gyouzhe.service.ISellerService;
import cn.gyouzhe.utils.Common;
import cn.gyouzhe.source.vo.GoodVo;

/**
 * 卖家保存处理器
 *
 * @author wangchuan
 * @datetime 2018/2/11 23:29
 */
class SellerStoreHandler extends AbstractHandler {
    private ISellerService sellerService;

    private ISellerService sellerService() {
        if(null == sellerService) {
            synchronized(this) {
                if(null == sellerService)
                    sellerService = Common.getBean(ISellerService.class);
            }
        }
        return sellerService;
    }


    @Override
    public void handle(Object data) {
        GoodVo goodVo = (GoodVo) data;
        String sellerId = goodVo.getSellerId();
        Seller seller = sellerService().selectSeller(sellerId);
        if(null == seller) {
            seller = Seller.of(sellerId, "");
            sellerService().saveSeller(seller);

        }
        goodVo.setStoreSellerId(seller.getId());
    }
}
